<?php

function getFileName($i)
{
    return 'jachi/jachi-'.$i.'.html';
}

function fetchURL($url)
{
        $context = stream_context_create(array("http"=>array(
                "method" => "POST",
                "header" => "Accept: xml/*, text/*, */*\r\n",
                "ignore_errors" => false,
                "timeout" => 50,
        )));
        ini_set("user_agent" , "Mozilla/5.0\r\nAccept: */*\r\nX-Padding: Foo");
        $page= file_get_contents($url, false, $context, 0);
    
        if($page==false)
            return false;
        if(strlen($page)<1000)
            return false;
    return $page;
}
for($i=1902;$i<=2020;$i++)
{
    $filename=getFileName($i);
    if(file_exists($filename))
        continue;
    $url='http://jieqi.911cha.com/'.$i.'.html';
    $page= fetchURL($url);
    if($page==false)
        continue;
    file_put_contents($filename,$page);
    echo "process".$i.PHP_EOL;    
}

//http://jieqi.911cha.com/1902.html